// Warp.h: interface for the CWarp class.
//
//////////////////////////////////////////////////////////////////////
#include "stdAfx.h"
#include <vector>
#include <math.h>
#include <math\mathlib.h>
#include <mkl.h>
#include "math\mkl_addon.h"

#if !defined(AFX_WARP_H__B29868C6_4C29_4468_8278_32A6581B2A1A__INCLUDED_)
#define AFX_WARP_H__B29868C6_4C29_4468_8278_32A6581B2A1A__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
using namespace std;
using namespace numc;
class Vector2;
struct matrix2 
{
	double c11,c12,c21,c22;
};

class CWarp  
{
protected:
	std::vector<Vector2> m_Src,m_Dst;

public:
	CWarp();
	virtual Vector2 Warping(Vector2 point)=0;	
	virtual ~CWarp();
};

class CMLS: public CWarp
{
public:
	CMLS();
	CMLS(vector<CPoint> &CtrPs, vector<CPoint> &CtrQs);
	CMLS(vector<Vector2> &CtrPs,vector<Vector2> &CtrQs);
	virtual Vector2 Warping(Vector2 point);	
};

class CIDW : public CWarp
{
public:
	CIDW();
	CIDW(std::vector<CPoint> &CtrPs,std::vector<CPoint> &CtrQs);
	CIDW(std::vector<Vector2> &CtrPs,std::vector<Vector2> &CtrQs);
	virtual Vector2 Warping(Vector2 point);
	~CIDW();

private:
	double InDistance(Vector2 pointP,Vector2 point);                //compute the inverse distance
	matrix2 ComputeMatrixD(Vector2 pointP,Vector2 pointQ);          //compute the transformation matrix        
	void    ComputeMatrix();                                      //compute the transformation matrices
private:
	matrix2 *m_Mat;
};

class  CRBF:public CWarp
{
public:
	double m_fR;	
	CRBF();
	CRBF(vector<CPoint>& CtrPs,vector<CPoint>& CtrQs);
	CRBF(vector<Vector2>& src, vector<Vector2>& dst,double _fR);
	virtual Vector2 Warping(Vector2 point);	
	~CRBF();
private:
	double ComputeRadial(Vector2 CtrP,Vector2 point);          //compute the radial basis
	void   ComputeCoeffi();                                  //compute the coefficients of the linear equations
private:
	double *m_solux;
	double *m_soluy;
};

#endif // !defined(AFX_WARP_H__B29868C6_4C29_4468_8278_32A6581B2A1A__INCLUDED_)
